<?php

/* -- TASK LIST -- */
echo "<form name='task_list' method='post'>\n";
echo "<table id='$css_table_id' cellspacing='0'>\n";
echo "<caption>Active Tasks:</caption>\n";
echo "<tr>\n";
echo "<th>Delete\n";
echo "<th align='center'>Id\n";
//echo "<th align='center'>Date\n";
echo "<th align='center'>Task\n";
echo "<th align='center'>Pri\n";
echo "<th align='center'>State\n";
echo "<th align='center'>%\n";
echo "<th align='center'>Done\n";
echo "<th align='center'>Total\n";
echo "<th align='center'>Time\n";
//echo "<th align='center'>Action\n";

foreach($tm->tasks as $task) {
	// Only list related tasks
	if($task->state != 1) {
		continue;
	}

	// Calculate the percentage
	$result = $task->complete / $task->total;

	// Make something readable from 'seconds'
	$sec = $task->seconds;
	$s = floor($sec % 60);
	$m = floor(($sec / 60) % 60);
	$h = floor(($sec / (60 * 60)) % 12);


	echo "<tr>\n";
	echo "<td>"
			. "<input type='submit'"
			." onClick=\"javascript:process('del_task', 'id=". $task->id."');\""
			." value='del'/>\n";

	echo "<td align='center'>". $task->id;
//	echo "<td align='center'>". date("m/d H:m:s", $task->timestamp);
	echo "<td align='center'>". $task->todo;
	echo "<td align='center'>";
	echo "<select name='priority' onChange='javascript:process("
		. "\"priority\",\""
		. "id=". $task->id
//		."|priority=\" + document.task_list.priority.selectedIndex"
		."|priority=\" + this.selectedIndex"
		. ")'>\n";
	for($ctr = 0; $ctr <= 5; $ctr ++) {
		if($task->priority == $ctr) {
			echo "<option selected>"
				. $task->priority
				. "</option>";
		}
		else {
			echo "<option>" . $ctr . "</option>";
		}
	}
	echo "</select>\n";
	switch($task->state) {
/*	case 0:
		echo "<td align='center'>Pending\n";
		echo "<td align='center'>&nbsp;\n";
		echo "<td align='center'>\n"
			."<form method='post'>\n"
			."<input type='submit' value='start'/>\n"
			."<input type='hidden' name='cmd' value='start'/>\n"
			."<input type='hidden' name='id' value='". $task->id ."'/>\n"
			."</form>\n";
		break;
*/	case 1:
		echo "<td align='center'>Active\n";
		echo "<td align='center'>". number_format(100 * $result, 2) ."%"."\n";
		echo "<td align='center'>". $task->complete ."\n";
		echo "<td align='center'>". $task->total ."\n";
		echo "<td align='center' nowrap>$h h $m m $s s\n";
		break;
	case 2:
		echo "<td align='center'>Complete\n";
		//echo "<td align='center'>100.00%\n";
		echo "<td align='center'>". number_format(100 * $result, 2) ."%"."\n";
		echo "<td align='center'>". $task->complete ."\n";
		echo "<td align='center'>". $task->total ."\n";
		echo "<td align='center' nowrap>$h h $m m $s s\n";
		break;
	}
//	echo "<td align='center'>\n";
//	echo "<a href='javascript:process(\"del_task\", \"id=". $task->id ."\");' />del</a>\n";
}
echo "</table>\n";
echo "</form>\n";

?>
